﻿#include"unordered_map.h"
#include"unordered_set.h"

struct Date
{
	Date(int year=0,int month=0,int day=0)
		:_year(year)
		,_month(month)
		,_day(day)
	{}

	bool operator==(const Date& date) const
	{
		return _year == date._year
			&& _month == date._month
			&& _day == date._day;
	}

	int _day;
	int _month;
	int _year;
};

struct DateHashFunc
{
	size_t operator()(const Date& date)
	{
		int ret = 0;
		ret += date._year;
		ret *= 131;
		ret += date._month;
		ret *= 131;
		ret += date._day;
		ret *= 131;

		return ret;
	}
};

void test1()
{
	//测试int类型
	hyc::unordered_map<int, int> map;
	map.insert({ 1,1 });
	map.insert({ 2,2 });
	map.insert({ 3,3 });
	for (auto& e : map)
	{
		cout << e.first << " " << e.second << endl;
	}

//	hyc0::unordered_map<int> set;
//	set.insert(1);
//	set.insert(2);
//	set.insert(3);
//	for (auto& e : set)
//	{
//		cout << e << " ";
//	}

}

void test2()
{
	//测试string类型
	hyc::unordered_map<string,string> map;
	map.insert({ "huang","huang"});
	map.insert({ "yu","yu"});
	map.insert({ "chi","chi"});
	for (auto& e : map)
	{
		cout << e.first << " " << e.second << endl;
	}

	//hyc0::unordered_map<string> set;
	//set.insert("huang");
	//set.insert("yu");
	//set.insert("chi");
	//for (auto& e : set)
	//{
	//	cout << e << " ";
	//}
}


void Print(Date date)
{
	cout << date._year << " " << date._month << " " << date._day << " " << endl;
}

void test3()
{

	//测试自定义类型
	hyc::unordered_map<Date, Date, DateHashFunc> map;
	Date r1({ 2025,4,7 });
	Date r2({ 2025,4,10});
	Date r3({ 2025,7,4 });
	map.insert({ r1,r1 });
	map.insert({ r2,r2 });
	map.insert({ r3,r3 });
	for (auto& e : map)
	{
		Print(e.first);
		Print(e.second);
	}

	//hyc0::unordered_map<Date, DateHashFunc> set;
	//Date r1({ 2025,4,7 });
	//Date r2({ 2025,4,10 });
	//Date r3({ 2025,7,4 });
	//set.insert( r1 );
	//set.insert( r2 );
	//set.insert( r3 );
	//for (auto& e : set)
	//{
	//	Print(e);
	//}
}

void test_map()
{
	hyc::unordered_map<string, string> dict;
	dict.insert({ "sort", "排序" });
	dict.insert({ "left", "左边" });
	dict.insert({ "right", "右边" });
	dict["left"] = "左边，剩余";
	dict["insert"] = "插⼊";
	dict["string"];
	hyc::unordered_map<string, string>::iterator it = dict.begin();
	while (it != dict.end())
	{
		// 不能修改first，可以修改second 
		//it->first += 'x';
/*		auto e = it->second*/;
		//cout << typeid(it->second).name() << endl;
		//cout << typeid(e).name() << endl;
		//e += 'x';
		it->second += 'x';

		cout << it->first << ":" << it->second << endl;
		++it;
	}
	cout << endl;
}


int main()
{
	test_map();
}